package com.sqstudio.common
{
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	/**
	 *提示管理器 
	 * @author Nestor
	 * 
	 */
	public class TipManager
	{
		private var _par:Sprite;
		private var _tip:Sprite;
		private var _yOff:int;
		private var _xOff:int;
		public function TipManager($_parent:Sprite,$_tip:Sprite,$_yOff:int=0,$_xOff:int=0)
		{
			this._par = $_parent;
			this._tip = $_tip;
			this._yOff = $_yOff;
			this._xOff = $_xOff;
			this._tip.visible = false;
			this._par.addEventListener(MouseEvent.MOUSE_OVER,overHandler);
		}
		
		private function overHandler(event:MouseEvent):void
		{
			this._tip.visible = true;
			DataProxy.setIndex(this._tip);
			this._par.removeEventListener(MouseEvent.MOUSE_OVER,overHandler);
			this._par.addEventListener(MouseEvent.MOUSE_MOVE,moveHandler);
			this._par.addEventListener(MouseEvent.MOUSE_OUT,outHandler);
		}
		
		private function moveHandler(e:MouseEvent):void
		{
			this._tip.x = e.stageX+this._xOff;
			this._tip.y = e.stageY+this._yOff ;
			if((this._tip.x+this._tip.width/2)>Sys.STAGE.stageWidth) this._tip.x=Sys.STAGE.stageWidth-this._tip.width/2
			if((this._tip.x-this._tip.width/2)<0) this._tip.x=this._tip.width/2
		}
		
		private function outHandler(event:MouseEvent):void
		{
			this._tip.visible = false;
			this._par.addEventListener(MouseEvent.MOUSE_OVER,overHandler);
			this._par.removeEventListener(MouseEvent.MOUSE_OUT,outHandler);
			this._par.removeEventListener(MouseEvent.MOUSE_MOVE,moveHandler);
		}
		

	}
}